package com.ha.controller.admin;

import com.ha.dto.BannerDTO;
import com.ha.dto.BannerPageDTO;
import com.ha.entity.Banner;
import com.ha.result.PageResult;
import com.ha.result.Result;
import com.ha.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: BannerController
 * Package: com.ha.controller.admin
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/5/2  19:18
 * @Version 1.0
 */
@RestController("AdminBanner")
@RequestMapping("/admin/banner")
@Api(tags = "轮播图接口")
@Slf4j
public class BannerController {

    @Autowired
    private BannerService bannerService;
    @PostMapping("/add")
    public Result addBanner(@RequestBody Banner banner){

        bannerService.addBanner(banner);
        return Result.success();
    }

    /**
     * 轮播图分页查询
     * @param bannerDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("轮播图分页查询")
    public Result<PageResult> page(BannerPageDTO bannerDTO){
        log.info("轮播图分页查询参数为 ：{}",bannerDTO);
        PageResult pageResult = bannerService.pageQuery(bannerDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/delete/{deleted}")
    @ApiOperation("轮播图删除")
    public Result delete(@PathVariable Integer deleted , Long id){
        bannerService.delete(id,deleted);
        return Result.success();
    }


    @PutMapping("/update")
    @ApiOperation("轮播图修改")
    public Result update(@RequestBody BannerDTO bannerDTO){
        bannerService.update(bannerDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<Banner> getById(@PathVariable Long id){
        Banner banner = bannerService.getById(id);
        return Result.success(banner);
    }
}
